#include "EWAUITrackBodyVideo.hpp"

#include "EWAPrjTrackUI.hpp"
#include "EWAColorSet.hpp"
#include "EWAPrjFragmentFragmentResourse.hpp"

namespace Eyer
{
    EWAUITrackBodyVideo::EWAUITrackBodyVideo(EyerSmartPtr<EWAUITimelineContext> _timelineCtx, EWAUILayoutParams _width, EWAUILayoutParams _height)
        : EWAUITrackBody(_timelineCtx, _width, _height)
    {
        SetWidgetName("EWAUITrackBodyVideo");
        SetLayoutType(EWAUILayoutType::FixedLayout);
    }

    EWAUITrackBodyVideo::~EWAUITrackBodyVideo()
    {

    }

    int EWAUITrackBodyVideo::OnDraw()
    {
        RemoveAllUIGraph();

        EWAPrjTrackType trackType = GetTrackType();
        int trackCount = timelineCtx->timeline.GetTrackCount(trackType);

        int offsetY = 0;

        // for(int i = 0; i < trackCount; i++){
        for(int i=trackCount - 1; i >= 0; i--) {
            EyerSmartPtr<EWAPrjTrackUI> track = timelineCtx->timeline.GetTrack(i, trackType);

            EyerSmartPtr<EWAUITrackHeaderItem> item = track->item;
            EyerSmartPtr<EWAUIWidgetVerticalSegBar> segBar = track->segBar;

            int segBarH = segBar->wh.height();
            {
                EyerSmartPtr<EWAUIGraphRect> rect(new EWAUIGraphRect());
                rect->xy.SetX(0);
                rect->xy.SetY(offsetY);
                rect->wh.width(wh.width());
                rect->wh.height(segBarH);
                rect->background = EyerColor::GRAY_34;
                AddUIGraph(rect);
            }
            offsetY += segBarH;

            int itemH = item->wh.height();
            {
                EyerSmartPtr<EWAUIGraphRect> rect(new EWAUIGraphRect());
                rect->xy.SetX(0);
                rect->xy.SetY(offsetY);
                rect->wh.width(wh.width());
                rect->wh.height(itemH);
                rect->background = EWAColorSet::TRACK_BODY_BG;
                AddUIGraph(rect);
            }
            offsetY += itemH;
        }

        OnDrawFragment();

        SetMinWH(2000, offsetY);

        /*
        EyerSmartPtr<EWAUIGraphRect> rect(new EWAUIGraphRect());
        rect->xy = xy;
        rect->wh = wh;
        rect->background = EyerColor::YELLOW;
        AddUIGraph(rect);

        SetMinWH(2000, 200);
         */
        return 0;
    }

    int EWAUITrackBodyVideo::OnDrawFragment()
    {
        return 0;
    }

    bool EWAUITrackBodyVideo::OnMousePressEvent     (const Vec2I & pos)
    {
        return true;
    }

    bool EWAUITrackBodyVideo::OnMouseReleaseEvent   (const Vec2I & pos)
    {
        return true;
    }

    bool EWAUITrackBodyVideo::OnMouseMoveEvent      (const Vec2I & pos)
    {
        return true;
    }

    EWAPrjTrackType EWAUITrackBodyVideo::GetTrackType()
    {
        return EWAPrjTrackType::VIDEO;
    }
}